home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / tcl / tcl67.lha / tcl6.7 / config < prev    next >
Text File  |  1993-02-10  |  11KB  |  355 lines

  1. #!/bin/csh -f
  2. #
  3. # This script should be executed to configure the Tcl source directory
  4. # for a particular system.  It probes the system for various header
  5. # files and library object files.  Where things needed by Tcl are missing,
  6. # substitute versions are included from the "compat" subdirectory.
  7. #
  8. # $Header: /user6/ouster/tcl/RCS/config,v 1.41 93/02/08 08:20:03 ouster Exp $ SPRITE (Berkeley)
  9. #
  10. # Copyright 1991, 1992 Regents of the University of California
  11. # Permission to use, copy, modify, and distribute this
  12. # software and its documentation for any purpose and without
  13. # fee is hereby granted, provided that this copyright
  14. # notice appears in all copies.  The University of California
  15. # makes no representations about the suitability of this
  16. # software for any purpose.  It is provided "as is" without
  17. # express or implied warranty.
  18.  
  19. #--------------------------------------------------------------
  20. # The variable definitions below configure this script:  they
  21. # tell where system-defined things are kept (so this program
  22. # can tell whether the system contains certain features needed
  23. # by Tcl), and they indicate which Tcl files to modify to
  24. # reflect the configuration.
  25.  
  26. # Directory containing system include files:
  27.  
  28. set includeDir="/usr/include"
  29.  
  30. # Places to look for archive file containing object code for standard
  31. # C library (the first existing file is used):
  32.  
  33. set libcFiles="/lib/libc.a /usr/lib/libc.a /lib/libc.so /usr/ccs/lib/libc.a"
  34.  
  35. # Makefile to modify:
  36.  
  37. set makefile="Makefile"
  38.  
  39. # Header file to modify to hold #defines about system configuration:
  40.  
  41. set config="tclUnix.h"
  42. #--------------------------------------------------------------
  43.  
  44. set changes=0
  45. unset time
  46.  
  47. # First make sure that the configuration variables have been
  48. # set in a reasonable fashion.
  49.  
  50. if ( ! -r $includeDir/stdio.h ) then
  51.     echo "- ERROR\!\! $includeDir doesn't seem to contain standard system"
  52.     echo "  include files.  Please edit config to set the includeDir"
  53.     echo "  variable."
  54.     exit(1)
  55. endif
  56. set libc=""
  57. foreach i ($libcFiles)
  58.     if ( -r $i ) then
  59.     set libc=$i
  60.     break
  61.     endif
  62. end
  63. if ( $libc == "" ) then
  64.     echo "- ERROR\!\! C library $libc doesn\'t exist.  Please edit config"
  65.     echo "  to set the libc variable."
  66.     exit(1)
  67. endif
  68.  
  69. # Extract name information from the C library archive.  Different systems
  70. # require different flags to nm, so the code below tries one way and sees
  71. # if it generates standard error output (can't just check $status because
  72. # on IBM systems the exit status is 0 even if there's an error).  If there's
  73. # a problem, try the operation again with a different set of switches.
  74.  
  75. (nm -p $libc > tmp.libc) >& tmp.err
  76. set a = `cat tmp.err`
  77. \rm tmp.err
  78. if ( $#a ) then 
  79.     nm -en $libc > tmp.libc
  80. endif
  81. if ( $status != 0 ) then
  82.     echo "- ERROR\!\!  Nm failed to extract names of system-supplied library"
  83.     echo "  procedures from $libc.  You'll have to modify config by hand to"
  84.     echo "  fix the problem (whatever it is)."
  85.     exit(1)
  86. endif
  87.  
  88. # Since nm produces different output on different machines, the code
  89. # below attempts to guess what pattern to grep for in the nm output.
  90.  
  91. set pattern="[ADIT]"
  92. set x=`grep printf tmp.libc | grep -c CODE`
  93. if ( $x ) then
  94.     set pattern=CODE
  95. endif
  96. set x=`grep printf tmp.libc | grep -c extern`
  97. if ( $x ) then
  98.     set pattern="|extern|"
  99. endif
  100.  
  101. # Check in the C library for particular library procedures and
  102. # variables needed by Tcl.
  103.  
  104. set gettod=`grep gettimeofday tmp.libc | grep -c "$pattern"`
  105. if ( $gettod > 1 ) set gettod=1
  106. set getwd=`grep getwd tmp.libc | grep -c "$pattern"`
  107. if ( $getwd > 1 ) set getwd=1
  108. set opendir=`grep opendir tmp.libc | grep -c "$pattern"`
  109. if ( $opendir > 1 ) set opendir=1
  110. set strerror=`grep strerror tmp.libc | grep -c "$pattern"`
  111. if ( $strerror > 1 ) set strerror=1
  112. set strncasecmp=`grep strncasecmp tmp.libc | grep -c "$pattern"`
  113. if ( $strncasecmp > 1 ) set strncasecmp=1
  114. set strstr=`grep strstr tmp.libc | grep -c "$pattern"`
  115. if ( $strstr > 1 ) set strstr=1
  116. set strtod=`grep strtod tmp.libc | grep -c "$pattern"`
  117. if ( $strtod > 1 ) set strtod=1
  118. set strtol=`grep strtol tmp.libc | grep -c "$pattern"`
  119. if ( $strtol > 1 ) set strtol=1
  120. set strtoul=`grep strtoul tmp.libc | grep -c "$pattern"`
  121. if ( $strtoul > 1 ) set strtoul=1
  122. set sys_errlist=`grep sys_errlist tmp.libc | grep -c "$pattern"`
  123. if ( $sys_errlist > 1 ) set sys_errlist=1
  124. \rm tmp.libc
  125.  
  126. # Next, install header files that aren't present in /usr/include.
  127.  
  128. set extraHdrs=""
  129. foreach i (dirent.h limits.h)
  130.     \rm -f $i
  131.     if ( ! -r $includeDir/$i ) then
  132.     cp compat/$i .
  133.     set extraHdrs="$extraHdrs $i"
  134.     endif
  135. end
  136. set stdlibOK=0
  137. \rm -f stdlib.h
  138. if ( -r $includeDir/stdlib.h ) then
  139.     # The check below is needed because SunOS has a stdlib that
  140.     # doesn't declare strtod and other procedures, so we have to
  141.     # use ours instead.
  142.  
  143.     set chk1=`grep -c strtol $includeDir/stdlib.h`
  144.     set chk2=`grep -c strtoul $includeDir/stdlib.h`
  145.     set chk3=`grep -c strtod $includeDir/stdlib.h`
  146.     if ( $chk1 > 0 && $chk2 > 0 && $chk3 > 0 ) then
  147.     set stdlibOK=1
  148.     endif
  149. endif
  150. if ( ! $stdlibOK ) then
  151.     cp compat/stdlib.h .
  152.     set extraHdrs="$extraHdrs stdlib.h"
  153. endif
  154.  
  155. # Even if string.h exists it's not complete on all systems.  If
  156. # some of the procedures we need are missing from the library, then
  157. # also install a Tcl-specific string.h.
  158.  
  159. \rm -f string.h
  160. if ( ! $strstr || ! $strtoul || ! $strncasecmp \
  161.     || ! -r $includeDir/string.h ) then
  162.     cp compat/string.h .
  163.     set extraHdrs="$extraHdrs string.h"
  164. endif
  165. if ( "$extraHdrs" != "" ) then
  166.     echo "- Substitutes will be used for the following header files,"
  167.     echo "  which aren't in ${includeDir} or aren't complete:"
  168.     echo "     $extraHdrs"
  169.     set changes=1
  170. endif
  171.  
  172. # Even if strtoul exists, it is bogus on some AIX systems.  Detect
  173. # this and pretend the system version doesn't exist if it's bogus.
  174.  
  175. if ( $strtoul ) then
  176.     cp compat/teststrtoul.c test.c
  177.     make configtest >& /dev/null
  178.     if ( $status == 0 ) then
  179.     ./a.out
  180.     if ( $status != 0 ) then
  181.         set strtoul=0
  182.     endif
  183.     endif
  184.     \rm -f a.out test.c
  185. endif
  186.  
  187. # Next, install C procedures for missing library functions.
  188.  
  189. set extraLibs=""
  190. \rm -f strerror.c
  191. if ( ! $strerror ) then
  192.     set extraLibs="$extraLibs strerror"
  193.     cp compat/strerror.c .
  194. endif
  195. \rm -f opendir.c
  196. if ( ! $opendir ) then
  197.     set extraLibs="$extraLibs opendir"
  198.     cp compat/opendir.c .
  199.     \rm -f dirent.h
  200.     cp compat/dirent2.h dirent.h
  201.     echo "- No opendir/readdir/closedir library exists in this system,"
  202.     echo "  so substitutes will be provided.  This system better have"
  203.     echo "  V7-style directories\!"
  204. endif
  205. \rm -f strncasecmp.c
  206. if ( ! $strncasecmp ) then
  207.     set extraLibs="$extraLibs strcasecmp"
  208.     cp compat/strcasecmp.c .
  209. endif
  210. \rm -f strstr.c
  211. if ( ! $strstr ) then
  212.     set extraLibs="$extraLibs strstr"
  213.     cp compat/strstr.c .
  214. endif
  215. \rm -f strtod.c
  216. if ( ! $strtod ) then
  217.     set extraLibs="$extraLibs strtod"
  218.     cp compat/strtod.c .
  219. endif
  220. \rm -f strtol.c
  221. if ( ! $strtol ) then
  222.     set extraLibs="$extraLibs strtol"
  223.     cp compat/strtol.c .
  224. endif
  225. \rm -f strtoul.c
  226. if ( ! $strtoul ) then
  227.     set extraLibs="$extraLibs strtoul"
  228.     cp compat/strtoul.c .
  229. endif
  230. if ( "$extraLibs" != "" ) then
  231.     echo "- Substitutes will be used for the following library procedures,"
  232.     echo "  which aren't in ${libc} or don't work correctly:"
  233.     echo "     $extraLibs"
  234.     set changes=1
  235. endif
  236.  
  237. # The following statements determine whether ranlib should be used
  238. # in the Makefile.  On System-V systems it shouldn't.  The only way
  239. # to figure this out is to run ranlib and see if it complains (ranlib
  240. # actually exists on some Sys-V systems, but it returns an error if
  241. # you run it).
  242.  
  243. set ranlibOK=0
  244. cat > ranlibtest.c << EOF
  245. #include <stdio.h>
  246. main (argc, argv)
  247.     int    argc;
  248.     char **argv;
  249. {
  250.     printf ("Hello, world.\n");
  251. }
  252. EOF
  253. cc -c ranlibtest.c
  254. ar cru ranlibtest.a ranlibtest.o
  255. ranlib ranlibtest.a >& /dev/null
  256. if ( $status == 0 ) then
  257.     set ranlibOK=1
  258. else
  259.     echo "- This system appears to be a System V one where ranlib isn't"
  260.     echo "  used.  The ranlib commands will be removed from Makefile."
  261.     set changes=1
  262. endif
  263. \rm -f ranlibtest.*
  264.  
  265. # Modify the Makefile to include supplemental library sources, if needed.
  266.  
  267. set compatObjs=""
  268. foreach i ($extraLibs)
  269.     set compatObjs="$compatObjs $i.o"
  270. end
  271. if ( ! -e $makefile.bak ) mv $makefile $makefile.bak
  272. if ( $ranlibOK ) then
  273.     sed -e "s/COMPAT_OBJS =/COMPAT_OBJS =$compatObjs/" $makefile.bak > $makefile
  274. else
  275.     sed -e "s/COMPAT_OBJS =/COMPAT_OBJS =$compatObjs/" \
  276.     -e "/ranlib/d" $makefile.bak > $makefile
  277. endif
  278.  
  279. # Set the #defines in tclUnix.h to provide various pieces of system
  280. # configuration information at compile time (existence of header files,
  281. # variables, type definitions, etc.)
  282.  
  283. if ( ! $gettod ) then
  284.     echo "- There's no gettimeofday in ${libc} so Tcl will use"
  285.     echo '  times for the "time" command.'
  286.     set changes=1
  287. endif
  288. if ( ! $getwd ) then
  289.     echo "- There's no getwd in ${libc} so Tcl will use"
  290.     echo '  getcwd for the "pwd" command.'
  291.     set changes=1
  292. endif
  293. set errlist=1
  294. if ( ! $sys_errlist && ! $strerror ) then
  295.     echo "- Neither strerror nor sys_errlist is defined in ${libc} so"
  296.     echo "  Tcl will make a guess about errno-related messages."
  297.     set errlist=0
  298.     set changes=1
  299. endif
  300. set sysTime=0
  301. if ( -r $includeDir/sys/time.h ) then
  302.     set sysTime=1
  303. endif
  304. set sysWait=0
  305. set unionWait=0
  306. if ( -r $includeDir/sys/wait.h ) then
  307.     set sysWait=1
  308.     cp compat/testwait.c test.c
  309.     make configtest >& /dev/null
  310.     if ( $status == 0 ) then
  311.     set unionWait=1
  312.     endif
  313.     \rm -f a.out test.c
  314. endif
  315. set pid_t=1
  316. cp compat/testpid.c test.c
  317. make configtest >& /dev/null
  318. if ( $status != 0 ) then
  319.     set pid_t=0
  320.     echo "- The type pid_t isn't defined in <sys/types.h> so Tcl will"
  321.     echo '  use "int" instead.'
  322. endif
  323. \rm -f a.out test.c
  324. set uid_t=1
  325. cp compat/testuid.c test.c
  326. make configtest >& /dev/null
  327. if ( $status != 0 ) then
  328.     set uid_t=0
  329.     echo "- The type uid_t isn't defined in <sys/types.h> so Tcl will"
  330.     echo '  use "int" instead.'
  331. endif
  332. \rm -f a.out test.c
  333. if ( ! -e $config.bak ) mv $config $config.bak
  334. set x=\.\*\$
  335. sed -e "s/define TCL_GETTOD 1/define TCL_GETTOD $gettod/" \
  336.     -e "s/define TCL_GETWD 1/define TCL_GETWD $getwd/" \
  337.     -e "s/define TCL_SYS_ERRLIST 1/define TCL_SYS_ERRLIST $errlist/" \
  338.     -e "s/define TCL_SYS_TIME_H 1/define TCL_SYS_TIME_H $sysTime/" \
  339.     -e "s/define TCL_SYS_WAIT_H 1/define TCL_SYS_WAIT_H $sysWait/" \
  340.     -e "s/define TCL_UNION_WAIT 1/define TCL_UNION_WAIT $unionWait/" \
  341.     -e "s/define TCL_PID_T 1/define TCL_PID_T $pid_t/" \
  342.     -e "s/define TCL_UID_T 1/define TCL_UID_T $uid_t/" \
  343. $config.bak > $config
  344.  
  345. if ( ! $changes ) then
  346.     echo "- No special modifications were needed for this system."
  347. endif
  348.  
  349. # Create a file that indicates that config completed successfully.
  350.  
  351. echo > configured "This file is created to indicate that the"
  352. echo >> configured '"config" script has been run to adjust'
  353. echo >> configured "Tcl's configuration for this site and that"
  354. echo >> configured "it completed successfully."
  355.